﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SubSonic;
using CXDB;
using Coolite.Ext.Web;
public partial class Scores_verify : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Store1Databind();
        }
    }
    protected void Store1Databind()
    {
        Query q = new Query(VwCompanyScoresGroupby.Schema);
        q.SetSelectList("companyid,companyname,electricname,tradename,status,scores_now,credit,guid,username,deptname,scores_pre");
        if (Cookies.getCookies("cdeptid") == "7")
        {
            q.AddWhere("depid",12);
        }
        if (Cookies.getCookies("cdeptid") == "10")
        {
             q.AddWhere("depid",SubSonic.Comparison.NotEquals,"12");             
        }
        q.AddWhere("status", SubSonic.Comparison.NotEquals, 2);
        Store1.DataSource = q.ExecuteDataSet();
        Store1.DataBind();
    }
    protected void Store1_OnRefreshData(object s, StoreRefreshDataEventArgs e)
    {
        Store1Databind();
    }
    protected void StoreDetail_onRefresh(object sender, StoreRefreshDataEventArgs e)
    {
        string id = e.Parameters["guid"];

        Query q = new Query(VwChengxindetail.Schema);
        q.SetSelectList("id,companyid,guid,scores,classname,tagname,detail,typename,shidu,basescores");
        q.AddWhere("guid", id);
        StoreDetail.DataSource = q.ExecuteDataSet();
        StoreDetail.DataBind();
    }
    protected void Allow(object s, AjaxEventArgs e)
    {
        if (e.ExtraParams["cmd"].ToLower() == "allow")
        {
            int count = new Select(new Aggregate("scores", "scores", AggregateFunction.Sum),
                           new Aggregate("guid", "guid", AggregateFunction.GroupBy)).From(CxChengxin.Schema)
                    .Where("guid").IsEqualTo(e.ExtraParams["guid"]).ExecuteScalar<int>();
            Query q = new Query(CxCompanyBase.Schema);
            q.AddUpdateSetting("scores", count);
            q.AddUpdateSetting("credit", Credit(count));
            q.AddWhere("companyid", e.ExtraParams["companyid"]);
            q.Execute();

            Query q1 = new Query(CxChengxin.Schema);
            q1.AddUpdateSetting("status", 1);
            q1.AddWhere("guid", e.ExtraParams["guid"]);
            q1.Execute();
        }
        if (e.ExtraParams["cmd"].ToLower() == "unallow")
        {
            Query q = new Query(CxChengxin.Schema);
            q.AddUpdateSetting("status", 2);
            q.AddWhere("guid", e.ExtraParams["guid"]);
            q.Execute();
        }
        Err.Warning("批复成功！",MessageBox.Icon.NONE);
    }
    protected string Credit(int i)
    {
        if ((i >= 95) && (i <= 100))
        {
            return "AAA";
        }
        if ((i < 95) && (i >= 85))
        {
            return "AA";
        }
        if ((i < 85) && (i >= 75))
        {
            return "A";
        }
        if ((i < 75) && (i >= 60))
        {
            return "B";
        }
        return "C";
    }
}
